package fpt.edu.vn.action;

import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import fpt.edu.vn.dao.UsersDao;
import fpt.edu.vn.model.Topics;

/* 
 * ProfileUserAction.java
 *  
 * 0.1
 * 
 * 10/15/2012 
 *  
 * Copyright notice 
 *  
 * Modification Logs: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  -------------------------------------------------------- 
 *  15-Oct-2012  ThuongND    Create new 
 */
public class ProfileUserAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private List<Object> users;
	private String email;
	private String Username;
	private int userId;
	private List<Topics> topics;
	private List<Topics> ownerTopics;
	private List<Topics> ownerFavorite;
	Map<String, Object> session;
	private UsersDao dao = new UsersDao();

	public String execute() {
		this.users = dao.list(email);
		String displayNamess = "";
		int userId_ = 0;
		session = ActionContext.getContext().getSession();
		if (session.containsKey("userIdss")) {
			userId_ = (Integer) session.get("userIdss");
			setUserId(userId_);
		}else{
			return ERROR;
		}
		this.topics = dao.countNumberPost(userId);
		if (session.containsKey("displayNamess")) {
			displayNamess = (String) session.get("displayNamess");
		}
		if ("".equals(displayNamess) || displayNamess == null) {
			setUsername(null);
		} else {
			setUsername(displayNamess);
		}
		if (session.containsKey("emailss")) {
			String emailss = (String) session.get("emailss");
			setEmail(emailss);
		}
		users = dao.list(email);
		this.ownerTopics = dao.listOwnerTopic(userId);
		this.ownerFavorite = dao.listOwnerFavorite(userId);

		return SUCCESS;
	}

	public List<Object> getUsers() {
		return users;
	}

	public void setUsers(List<Object> users) {
		this.users = users;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getUsername() {
		return Username;
	}

	public void setUsername(String username) {
		Username = username;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public List<Topics> getTopics() {
		return topics;
	}

	public void setTopics(List<Topics> topics) {
		this.topics = topics;
	}

	public List<Topics> getOwnerTopics() {
		return ownerTopics;
	}

	public void setOwnerTopics(List<Topics> ownerTopics) {
		this.ownerTopics = ownerTopics;
	}

	public List<Topics> getOwnerFavorite() {
		return ownerFavorite;
	}

	public void setOwnerFavorite(List<Topics> ownerFavorite) {
		this.ownerFavorite = ownerFavorite;
	}

}
